package com.sm42.goodsController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sm42.baseController.BaseCrmpController;
import com.sm42.common.http.AxiosResult;
import com.sm42.common.page.PageBean;
import com.sm42.goodsEntity.Type;
import com.sm42.goodsService.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("type")
public class TypeController extends BaseCrmpController<Type> {
    @Autowired
    private TypeService typeService;
    /**
     * 根据商品类型进行查询
     */
    @GetMapping("findTypeName")
    public AxiosResult<List<Type>> findTypeName(String type){
        return AxiosResult.success(typeService.findTypeName(type));
    }
    /**
     * 根据id进行删除
     */
    @GetMapping("deleteType")
    public AxiosResult deleteType(Long id){
        int row = typeService.deleteType(id);
        return toAxios(row);
    }
    /**
     * 根据id进行查询
     */
    @GetMapping("findTypeById")
    public AxiosResult<Type> findTypeById(Long id){
        return AxiosResult.success(typeService.findTypeById(id));
    }
    /**
     * 新增数据
     */
    @GetMapping("addType")
    public AxiosResult addType(Type type){
        return AxiosResult.success(typeService.addType(type));
    }
    /**
     * 修改数据
     */
    @GetMapping("updateType")
    public AxiosResult updateType(Type type){
        return AxiosResult.success(typeService.updateType(type));
    }
    /**
     * 模糊查询
     */
    @GetMapping("findSearch")
    public AxiosResult findSearch(Type type,Integer pageSize,Integer pageNum){
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);
        typeService.findSearch(type);
        return AxiosResult.success(PageBean.initData(page.getTotal(),page.getResult()));
    }
}
